<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head>
	<th:block th:include="include :: header('采购供应商列表')" />
	<style type="text/css">
		label.layui-form-label {width: 95px;padding-right: 0px;}
	</style>
</head>
<body>
<form>
    <div class="layuiadmin-header-box">
        <th:block th:include="listinclude :: searchTop" />
    </div>
</form>
<div class="mid-content">
    <table class="layui-hide" id="dhtable" lay-filter="ftable"></table>
</div>
<script type="text/html" id="toolbar">
	<div class="layui-btn-container">
        <div class="layui-btn layui-btn-normal layui-table-tools" onclick="$.operate.add()" th:if="${extraButton.add}">
            <p class="dhicon dh-plus" style="color:white;font-size:14px"><span class="fa_span">新增</span></p>
        </div>
		<div class="layui-btn layui-btn-danger layui-table-tools" onclick="remove()" th:if="${extraButton.deletes}">
            <p class="dhicon dh-remove" style="color:white;font-size:14px"><span class="fa_span">批量删除</span></p>
        </div>
    </div>
</script>
<script type="text/html" id="barDh">
	<a class="layui-btn layui-btn-xs dhicon dh-edit" onclick="$.operate.edit('{{d.guid}}',1000)"  th:if="${extraButton.update}">&nbsp;编辑</a>
	<a class="layui-btn layui-btn-disabled layui-btn-xs dhicon dh-edit"  th:if="!${extraButton.update}">&nbsp;编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs dhicon dh-remove" onclick="remove('{{d.guid}}')" th:if="${extraButton.delete}">&nbsp;删除</a>  
    <a class="layui-btn layui-btn-disabled layui-btn-xs dhicon dh-remove" th:if="!${extraButton.delete}">&nbsp;删除</a>  
</script>
<script type="text/html" id="templet_deleted">
    <input type="checkbox" value="{{d.guid}}" lay-skin="switch" lay-text="启用|停用" lay-filter="deleted" {{ d.deleted? '' : 'checked' }}>
</script>
<th:block th:include="include :: footer" />
<script th:inline="javascript">
	/*<![CDATA[*/
	var prefix = ctx + "purchase/purchasingsupplier";
	var gridColumns = [[${gridColumns}]];
	var moduleTable=[[${moduleTable}]];
	var extraButton=[[${extraButton}]];
    console.log("extraButton",extraButton)
	/*]]>*/
</script>
<script type="text/javascript">
var $,layer,form,table,wherestr={};
layui.use(['table','form','layer','jquery'], function () {
     $ = layui.$,layer = layui.layer,form = layui.form,table = layui.table;
     $.tablelist.init({
         elem: '#dhtable'
	     ,modalName: "采购供应商"
         ,url: prefix + '/list'
         ,createUrl: prefix + "/add"
         ,updateUrl: prefix + "/edit?guid={id}"
         ,initSort: {field: 'partnerId',type: 'asc'}
         ,totalRow: gridColumns.totalRow
   		 ,cols: [gridColumns.gridBody
 		 ]
        ,toolbar: '#toolbar'
   		,defaultToolbar: [{title:'列设置',layEvent: 'fieldSet',icon: 'layui-icon-set'}] //这里在右边显示
        ,height:'full-90'
     });
	//监听排序事件 
     table.on('sort(ftable)', function(obj){
     	$.tablelist.sort('dhtable',obj);
     });
   //头工具栏事件
 	table.on('toolbar(ftable)', function(obj){
 	    switch(obj.event){
 	    	case 'fieldSet':
 	    		filedSet(moduleTable);
          	break;
 	    };
 	});
 	//搜索按钮
 	$('#btn-search').on('click', function () {
 		$.each(wherestr,function(i,v){$("#"+i).val()?wherestr[i]=$("#"+i).val():wherestr[i]='';});//动态获取条件的值
        table.reload('dhtable', {page: {curr: 1},where:wherestr});
     });
 	//监听下拉框——添加条件
 	form.on('select(fft)', function(obj){
 		addMore(this);
 	});
 	//监听开关动作
	form.on('switch(deleted)', function(obj){
  	    if(obj.elem.checked==true){
  	    	$.operate.post(prefix + "/editpost", {'infoItems':JSON.stringify([{"guid":obj.value,"deleted":"0"}])});
	    }else{
	    	$.operate.post(prefix + "/editpost", {'infoItems':JSON.stringify([{"guid":obj.value,"deleted":"1"}])});
 		    }
  	    });
 });
//删除和批量操作
function remove(guid){
	if(guid){
		$.operate.remove("该删除无法恢复，请确认？",prefix + "/delete/",{'infoItems':JSON.stringify([{'guid':guid}])},function(result){
			allReload(result)
		});
	}else{
		if(table.checkStatus('dhtable').data.length>0){
			$.operate.remove("是否彻底删除选中的"+table.checkStatus('dhtable').data.length+"条数据？",prefix + "/delete/",{'infoItems':JSON.stringify(table.checkStatus('dhtable').data, null, 2)},function(result){
				allReload(result)
			});
		}else{
			layer.msg("无勾选数据！");
		};
	}
}
//刷新
function allReload(result){
    if(result.code==0){
        setTimeout(function(){
            layer.closeAll();
            table.reload('dhtable');
        }, 1000);
    }
}
</script>
</body>
</html>